		window.onload = function(){
			var oD1 = document.getElementById('d1');
			var oD2 = document.getElementById('d2');
			var oSpan = document.getElementById('osp');
			var oImg2 = document.getElementById('img2');

			oD1.onmouseover = function(){
				oSpan.style.display = 'block';
				oD2.style.display = 'block';
				document.onmousemove = function(ev) {
					var oEvent = ev || event;
					var l = oEvent.clientX - oSpan.offsetWidth / 2 - oD1.offsetLeft;
					var t = oEvent.clientY - oSpan.offsetHeight / 2 - oD1.offsetTop;
					if(l < 0) {
						l = 0
					};
					if(t < 0) {
						t = 0
					};
					if(l > oD1.offsetWidth - oSpan.offsetWidth) {
						l = oD1.offsetWidth - oSpan.offsetWidth - 2
					};
					if(t > oD1.offsetHeight - oSpan.offsetHeight) {
						t = oD1.offsetHeight - oSpan.offsetHeight - 2
					};
					var ml = l / (oD1.offsetWidth - oSpan.offsetWidth - 2) * (oD2.offsetWidth - 2 - oImg2.offsetWidth);
					var mt = t / (oD1.offsetHeight - oSpan.offsetHeight - 2) * (oD2.offsetHeight - 2 - oImg2.offsetHeight);
					oSpan.style.left = l +'px';
					oSpan.style.top = t + 'px';
					oImg2.style.left = ml + 'px';
					oImg2.style.top = mt + 'px';
				}
				oD1.onmouseout = function(){
					document.onmousemove = null;
					oSpan.style.display = 'none';
					oD2.style.display = 'none';
				}
			}
		}
		$(".plus").on("click",function(){
			var value=parseFloat($("#PieceproductNum").val())+1;
			$("#PieceproductNum").val(value);
			var total = (value*2.80).toFixed(2)
			$("#totalPrice").text(total)
		})
		$(".jian").on("click",function(){
			var value=parseInt($("#PieceproductNum").val())-1;
			$("#PieceproductNum").val(value=value<1?1:value);
			var total = (value*2.80).toFixed(2)
			$("#totalPrice").text(total)
		})
		$("#PieceproductNum").blur(function(){
			if($(this).val()<=0){
				$(this).val("1");
			} 
		})	
		var regex="\/";
		var picsrc=$("#d1>img").attr("src").split(regex);
//		$("#d1>img").attr("src");
		
		
//		console.log($("#totalPrice").text());
		$("#Oksubmit").on("click",function(){
			if($.cookie().name){
				$.post("/carts",
					{
						product:$(".dm").text(),
						count:$("#PieceproductNum").val(),
						unitPrice:Number($("#unit-price").text()),
						price:Number($("#totalPrice").text()),
						picsrc:picsrc[1]  
					},function(res){
						if(res.err==0){
							location.href="/shoppingCar_login"
						}
					});
			}else{
				location.href='/login'
			}
		})	